faApp.controller('ProductNoticeListCtrl',['$scope','productService','$location','$controller','$route','$routeParams','sessionService',function($scope,productService,$location,$controller,$route,$routeParams,sessionService) {   
  $controller('BaseListCtrl', {$scope: $scope}); 
  $scope.config = {
    "pageSize" : 20,
    "pageNo" : 1
  };
  $scope.chkProjectNoticeAll = function(){
    if($("#chkProjectNoticeAll").attr("checked") == "checked"){
      $("[name='chkProjectNotice']").attr("checked","checked");
    }else{
      $("[name='chkProjectNotice']").attr("checked",false);
    }
  }
  $scope.$watch('config',function(){
    productService.queryProductNoticeList($scope.config).then(function(json){
      $scope.list = json.list;
      $scope.pager = json.pager;
      $scope.loading = false;
    });
  },true);

  $scope.del = function(id){
    if(confirm("确认删除???")){
      $scope.config.id=id;
      $scope.config.deleteTag=2;
      productService.editProductNotice($scope.config).then(function(json){
        if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
           alert("删除成功!!");
           $route.reload();
        }
      });
    }
   
  }
  $scope.allDel = function(){
    var id="";
    $("[name='chkProjectNotice']").each(function(){
      if($(this).attr("checked") == "checked"){
          id += $(this).attr("value")+",";
      }
    });
    if(!id){
      alert("请选择资讯!!!");
      return ;
    }
    if(confirm("确认全部删除???")){
      id = id.substring(0, id.length - 1);
      $scope.config.id=id;
      $scope.config.deleteTag=2;
      productService.editProductNotice($scope.config).then(function(json){
        if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
           alert("删除成功!!");
           $route.reload();
        }
      });
    }
   
  }
  
  $scope.pageChanged = function(){
    $scope.config.pageNo = $scope.pager.pageNo;
  };   
}]);

faApp.controller('ProductNoticeDetailCtrl',['$scope','productService','$location','$controller','$route','$routeParams','sessionService','$sce',function($scope,productService,$location,$controller,$route,$routeParams,sessionService,$sce) {   
  $controller('BaseListCtrl', {$scope: $scope}); 
  $scope.config={};
  $scope.config.id = $routeParams.id;
  productService.queryProductNoticeDetail($scope.config).then(function(json){
      $scope.productNotice = json.queryProdcutNoticeDetail;
      $scope.productNotice.pContent=$sce.trustAsHtml($scope.productNotice.pContent);
      $scope.loading = false;
    });
   $scope.del = function(id){

    // $location.path("/productnotice/list");
      if(confirm("确认删除???")){
        $scope.config.id=id;
        $scope.config.deleteTag=2;
        productService.editProductNotice($scope.config).then(function(json){
          if (json.statusCode){
            alert("出错了:" + json.statusCode);
          }else{
            alert("删除成功!!");
            // $location.path("#/productnotice/list");
            window.parent.location = "#/productnotice/list";
          }

        });
      }

   }

   $scope.passVerifyable=function (id) {
    $scope.productNotice={};
    $scope.productNotice.id=id;
    $scope.productNotice.status=2;
    productService.editProductNotice($scope.productNotice).then(function(json){
       if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
          alert("审核成功!!");
          $route.reload();
         // window.parent.location = "#/productnotice/list";
        }
    });
   }
  $scope.productPassPublish=function (id) {
    $scope.productNotice={};
    $scope.productNotice.id=id;
    $scope.productNotice.onlineStatus=2;
    productService.editProductNotice($scope.productNotice).then(function(json){
       if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
          alert("发布成功!!");
          window.parent.location = "#/productnotice/list";
          //$route.reload();
        }
    });
   }
}]);

faApp.controller('ProductNoticeEditCtrl',['$scope','productService','$location','$controller','$route','$routeParams','sessionService',function($scope,productService,$location,$controller,$route,$routeParams,sessionService) {   
  $controller('BaseListCtrl', {$scope: $scope}); 
  $scope.config={};
  $scope.config.id = $routeParams.id;
  productService.queryProductNoticeDetail($scope.config).then(function(json){
      $scope.productNotice = json.queryProdcutNoticeDetail;
      $scope.loading = false;
  });

  $scope.save = function(){
    productService.editProductNotice($scope.productNotice).then(function(json){
       if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
          alert("编辑成功!!");
          if($scope.productNotice.onlineStatus==1){
            window.parent.location ="#/productnotice/base?id=" + $scope.productNotice.id;
          }else{
            window.parent.location = "#/productnotice/list";
          }
          //$route.reload();
        }
    });
  }

}]);


faApp.controller('ProductNoticeBaseCtrl',['$scope','productService','$location','$controller','$route','$routeParams','sessionService',function($scope,productService,$location,$controller,$route,$routeParams,sessionService) {   
  $controller('BaseListCtrl', {$scope: $scope}); 
  
  $scope.id = $routeParams.id;
  $scope.tabUrl = {};
  $scope.tabUrlMap = {
    detailUrl : "#/productnotice/detail?id=" + $scope.id,
    editUrl : "#/productnotice/edit?id=" + $scope.id
  };
  
  $scope.changeTab = function(tab){
    $scope.tabUrl[tab] = $scope.tabUrlMap[tab];
    sessionService.setItem("lastProductTab",tab);
  };
  
  var lastProductTab = sessionService.getItem('lastProductTab') || 'detailUrl'; 
  $scope.changeTab('detailUrl');
  
  $scope.pathText ="成立公告"; 
  
  angular.element(document).ready(function(){
    // console.log(1);
    if ($(window).height() > 300) $scope.iframeHeight = $(window).height() - 130;
  });

}]);


